import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/all/movie',  // 重定向:重新指向其它path,会改变网址
  },
  {
    path: '/all',
    name: 'all',
    // 路由懒加载
    component: () => import(/* webpackChunkName: "about" */ '../page/all.vue'),
    children:[
        {
            path: '/all/movie',
            name: 'movie',
            component:()=>import("../page/movie.vue"),
            meta:{
                name:"猫眼电影"
            }
           
        },
        {
            path: '/all/vuex',
            name: 'vuex',
            component:()=>import("../page/vuex.vue"),
            meta:{
                name:"vuex"
            }
           
        },
        {
            path: '/all/show',
            name: 'show',
            component:()=>import("../page/show.vue"),
            meta:{
                name:"猫眼演出"
            }
        },
    ]
  },
  {
    path: '/my',
    name: 'my',
    // 路由懒加载
    component: () => import(/* webpackChunkName: "about" */ '../page/my.vue'),
    beforeEnter(to,from,next){
        console.log(to,"to");
        console.log(from,"from")
        if (window.localStorage.getItem("isLogin")=="true"){
            next()
        } else {
            next("/login")
            // router.push("要去的路由")
        }
        // 放行
      
    },
    meta:{
        name:"我的"
    }
  },
  {
    path: '/login',
    name: 'login',
    // 路由懒加载
    component: () => import(/* webpackChunkName: "about" */ '../page/login.vue')
  },
  {
    path: '/zhuce',
    name: 'zhuce',
    // 路由懒加载
    component: () => import(/* webpackChunkName: "about" */ '../page/register.vue')
  },
  {
    path: '/detail',
    name: 'detail',
    // 路由懒加载
    component: () => import(/* webpackChunkName: "about" */ '../page/detail.vue')
  },
  // 错误路由配置，必须写在最下面
  {
    path: '*',
    // 路由懒加载
    component: () => import(/* webpackChunkName: "about" */ '../page/notFond.vue')
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router



